<?php
include "../inc-config.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Post</title>
<style type="text/css">
<!--
body {
	background-color: #000000;
	background-image: url(../images/alliance-tile.jpg); background-repeat:repeat-x;
}
body,td,th {
	color: #CC9900;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 13px;
}
a:link {
    color:#CC9900; 
	
	
}
a:visited {
    color:#CC9900;
	
}
a:hover {
    color:#ffffff;
}
a:active {
    color:#FF0000;
}	


input { background:transparent; background-image:url(../images/transp.png); color:#FFFFFF; border: 1px solid #333333}
select { background-color:#000000; color:#FFFFFF; border: 1px solid #333333}
textarea { background-color:#000000; color:#FFFFFF; border: 1px solid #333333}

-->
</style></head>

<body>

<center>
<?php
$user = $_SESSION['user'];
$getuser = "SELECT * from b_users a, b_templates b where b.templateid=a.templateclass and a.username='$user'";
$getuser2 = mysql_query($getuser, $forum) or die("Could not get user info");
$getuser3 = mysql_fetch_array($getuser2);
if(isset($_POST['ID']))
{
	$ID = $_POST['ID'];
}
else
{
	$ID = $_GET['ID'];
}
$checking = "SELECT * from b_posts,b_users where b_users.userID=b_posts.author and b_posts.ID='$ID'";
$checking2 = mysql_query($checking, $forum);
$checking3 = mysql_fetch_array($checking2);

if(strlen($getuser3[username])>1)
{
	$templateclass=$getuser3['templatepath'];
}
else
{
	$templateclass="default";
}
if($checking3['userID'] == $getuser3['userID'] || $getuser3['status'] > $checking3['status'])
{
	if(isset($_POST['edit']))
	{
		if(!$_POST['post'])
		{
			echo "<table>";
			echo "<tr class='headline'><td><center><strong>Edit Failed</strong></center></td></tr>";
			echo "<tr class='forumrow'><td><center>";
			echo "One of the required fields was not filled in, please go back and try again";
			echo "</td></tr></table>";
		}
		else
		{
			$title=$_POST['title'];
			$post=$_POST['post'];   
			if($_POST['nosmiley'])
			{
				$nosmiley = 1;
			}
			else
			{
				$nosmiley = 0;
			}
			$title = htmlspecialchars($title);
			$post = strip_tags($post,'<p><a><b><i><img><u><font>[url][img][URL][IMG][FONT][font]<sub><sup><span><li><size>[list][o][size][s][mail]');
			$update1 = "Update b_posts SET title='$title', post='$post',nosmilies='$nosmiley' where ID='$ID'";
			mysql_query($update1, $forum);
			echo "<table class='maintable'>";
			echo "<tr class='headline'><td><center>Edit</center></td></tr>";
			echo "<tr class='forumrow'><td><center>";
			if($checking3['threadparent']!='0')
			{
				echo "Post has been edited. Redirecting to topic... <META HTTP-EQUIV = 'Refresh' Content = '1; URL =index.php?forumID=$forumID&ID=$checking3[threadparent]'>";
			}
			else
			{
				echo "Post has been edited. Redirecting to topic... <META HTTP-EQUIV = 'Refresh' Content = '1; URL =index.php?forumID=$forumID&ID=$checking3[ID]'>";
			}
			echo "</td></tr></table>";
		}
	}
	else
	{
		echo "<br><br><br><br><table style='border: 1px solid #000000; background-image: url(../images/transp.png)'>";
		echo "<tr ><td style='background-image: url(../images/transpblack.png)'><center><strong>Edit</strong></center></td></tr>";
		echo "<tr ><td><center>";
		echo "<table border='0'><tr><td>";
		echo "<form action='edit.php' method='post' name='form'>";
		echo "<input type='hidden' name='name' value=$checking3[author]><br>";
		echo "<b>Name:</b> $user<br><br>";
		echo "<input type='hidden' name='ID' value='$ID'>";
		echo "<b>Topic:</b> ";
		echo "<input type='text' name='title' length='15' value='$checking3[title]'><br><br>";
		echo "<b>Message: <a target='_blank' href='bbcode.html'>(BBCode On)</a></b><br>";
		echo "<textarea rows='12' name='post' cols='45' id='7'>$checking3[post]</textarea><br><br>";
		echo "<input type='checkbox' name='nosmiley'>&nbsp;Disable Smilies<br><br>";
		echo "<input type='submit' name='edit' value='edit'>";
		echo "</form>";
	}
}
else
{
	echo "<table class='maintable'>";
	echo "<tr class='headline'><td><center>Edit</center></td></tr>";
	echo "<tr class='forumrow'><td><center>";
	echo "You do not have permission to edit this post";
	echo "</td></tr></table>";
}
 
?>
<br /><br />

</td>
</tr>
</table>

</center>   
</body>
</html> 